package iface.aplicativo.extensao.primefaces;

import java.io.IOException;
import java.util.Iterator;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;

import org.primefaces.component.menubar.MenubarRenderer;

public class MenubarExtensao extends MenubarRenderer {

	@Override
	protected void encodeMenuContent(FacesContext context, UIComponent component)
			throws IOException {
		ResponseWriter writer = context.getResponseWriter();

		for (Iterator<UIComponent> iterator = component.getChildren()
				.iterator(); iterator.hasNext();) {
			UIComponent child = (UIComponent) iterator.next();

			if (child != null && child.isRendered()) {

				writer.startElement("li", null);

				if (child instanceof MenuItemExtensao) {
					encodeMenuItem(context, (MenuItemExtensao) child);
				} else if (child instanceof SubmenuExtensao) {
					if (((SubmenuExtensao) child).getMenuItemExtensao() != null) {
						encodeMenuItem(context,
								((SubmenuExtensao) child).getMenuItemExtensao());
					} else {
						encodeSubmenu(context, (SubmenuExtensao) child);
					}
				}

				writer.endElement("li");
			}
		}
	}

}